/**
 * 此 js 的作用:
 *      1. 根据权限铺开前端页面的模块图标、链接
 *      2. 根据当前页的地址, 将对应的图标改为高亮模式
 *      3. 别瞎改, 真难写.....
 */

window.onload = function () {

    $.get("/user/loginInfo", function (resp) {

        if (resp.message !== "Error") {

            let liBro = $('#liBro');
            let li, a, image;

            // 判定当前页面的标识
            let tab = window.location.pathname.substring(window.location.pathname.indexOf('/', 2) + 1, (window.location.pathname.lastIndexOf('_')));

            for (let i of resp.data) {

                li = $('<li></li>');
                a = $('<a href="' + i.linkAddress + '"></a>');

                let newTab = i.icon.substring(i.icon.lastIndexOf('/') + 1, i.icon.lastIndexOf('_'));


                if ((tab === 'user' && newTab === 'information') || (tab === 'user_modi' && newTab === 'password') || (tab === newTab)) {

                    i.icon = i.icon.replace('out', 'on');
                }


                image = $('<img class="icon" src="' + i.icon + '"/>');

                a.append(image);
                li.append(a);
                liBro.before(li);
            }


        }


    })
};
